<?php

require_once 'Core/Db/Table/Abstract.php';
require_once 'Core/Db/Table/Row/Abstract.php';
require_once 'Core/Db/Table/Rowset/Abstract.php';

class Nld_Models_Jobs_Pro_DbTable extends Core_Db_Table_Abstract
{
	public function init()
	{
		$this->_name 						= 'vl_pro';
		$this->_primary 				= 'id';
		$this->_rowClass 				= 'Core_Db_Table_Row_Abstract';
		$this->_rowsetClass 		= 'Core_Db_Table_Rowset_Abstract';

		$this->_dependentTables = array(
			'Pro' 			=> Nld_Models::getTableClass('Jobs/Pro'),
		);
	}
	public function fetchChild($where = '`parentid` is null', 
		$whereex = null, $order = null, $level = 0)
	{
    $entries  = array();
    foreach($this->fetchAll(
			($whereex === null)?$where:$where.' AND '.$whereex, 
			($order === null)?array('order asc', 'id asc'):$order) as $entry)
		{
			$entries = array_merge(
									 $entries, 
									 array($entry->toArray()+array('_level' => $level)), 
									 $this->fetchChild('`parentid` = "'.$entry->id.'"', $whereex, $order)
									 			->toArray());
		}
		return $this->getRowSet($entries);
	}
}